using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using RushMail;

namespace Microsoft.Extensions.DependencyInjection;

public static class ServiceInjectExtension
{
    public static void AddRushMail(this IServiceCollection service, string customId, string secretKey)
    {
        service.AddScoped<IRushMailClient, RushMailClient>(sp => new RushMailClient(customId, secretKey, logger: sp.GetRequiredService<ILogger<RushMailClient>>()));
    }
    
    public static void AddRushMail(this IServiceCollection service, IConfiguration configuration)
    {
        var customId = configuration["Rushmail:customId"];
        var secretKey = configuration["Rushmail:secretKey"];
        service.AddScoped<IRushMailClient, RushMailClient>(sp => new RushMailClient(customId, secretKey, logger: sp.GetRequiredService<ILogger<RushMailClient>>()));
    }
}